package cn.edu.njust.alg.leetcode;

public class Leetcode_69_sqrt {

	/*
	 * 
	 * Implement int sqrt(int x).
	 * 
	 * Compute and return the square root of x.
	 */

	public static int mySqrt(int x) {
		if (x < 1) {
			return 0;
		}
		double m, n;
		m = 0;
		n = x / 2;
		while (m != n) {
			m = n;
			n = (m + x / m) / 2;
		}
		return (int)m;
	}

	public static void main(String[] args) {

		for(int i=1;i<50;i++){
			System.out.println(i+": "+mySqrt(i));
		}
	}

}
